package main

import (
	"encoding/json"
	"fmt"
	"github.com/lexkong/log"
	"github.com/spf13/pflag"
	"os"
	"shortURL/api"
	"shortURL/config"
	v "shortURL/pkg/version"
)

var (
	cfg     = pflag.StringP("config", "c", "", "config file path.")
	mod     = pflag.StringP("mod", "m", "", "run service mod")
	version = pflag.BoolP("version", "v", false, "show version info.")
)

func main() {
	pflag.Parse()

	if *version {
		v := v.Get()
		marshalled, err := json.MarshalIndent(&v, "", "  ")
		if err != nil {
			fmt.Printf("%v\n", err)
			os.Exit(1)
		}

		fmt.Println(string(marshalled))
		return
	}

	if err := config.Init(*cfg); err != nil {
		panic(err)
	}

	switch *mod {
	case "api":
		api := &api.Api{}
		api.Run()
		break
	default:
		log.Infof("mod not found: %s", *mod)
	}
}
